<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
	<title>Document</title>
	<link rel="stylesheet" href="./Tpl/css/bootstrap.min.css">
	<style type="text/css">
		.main{
			margin-top: 100px;
		}

	</style>
</head>
<body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <?php if(isset($_SESSION['nikename'])) { ?>
                <div class="navbar-form navbar-right">
                  <p  class="btn btn-danger"><?php echo $_SESSION['nikename'] ?></p>
                  <a href="./loginout.php" class="btn btn-success">退出</a>
                </div>
           <?php }else{ ?>
              <form action="./login.php" method="post" class="navbar-form navbar-right">
                <div class="form-group">
                  <input type="text" placeholder="用户名" class="form-control" name="username">
                </div>
                <div class="form-group">
                  <input type="password" placeholder="密码" name="password" class="form-control">
                </div>
                <button type="submit" class="btn btn-success">登录</button>
                <a href="./register.php" class="btn btn-success">注册</a>
              </form>
          <?php  } ?>
          
        </div><!--/.navbar-collapse -->
      </div>
    </nav>


    <div class="container main">
      <nav aria-label="Page navigation">
        <ul class="pagination">

          <?php if($page<>1){ ?>
              <li>
                <a href="./index.php?p=<?php echo $page-1; ?>" aria-label="Previous">
                  <span aria-hidden="true">上一页</span>
                </a>
              </li>
          <?php } ?>
          
          <?php for ($i=1; $i <=$pages ; $i++) { ?>
   
            <li><a href="./index.php?p=<?php echo $i ?>"><?php echo $i ?></a></li>
  
          <?php } ?>

          <?php if($page<>$pages){ ?>
              <li>
                <a href="./index.php?p=<?php echo $page+1; ?>" aria-label="Next">
                  <span aria-hidden="true">下一页</span>
                </a>
              </li>
          <?php } ?>
        </ul>
      </nav>
      <!-- Example row of columns -->
      <div class="row">
        <!-- 循环数据库数据在模板上 -->
      	<?php foreach ($shujuku as $k => $v) { ?>
      		
      	
	    	<div class="col-md-4 msgRow">
	          <h2><?php echo $v['username'] ?></h2>
	          <p><?php echo $v['content'] ?>(<?php echo date('Y-m-d H:i:s',$v['create_time']) ?>)</p>
	          <p><button xbsid="<?php echo $k ?>" class="btn btn-danger delBtn"  role="button">删除</button><a class="btn btn-info" href="./edit.php?id=<?php echo $k ?>" role="button">修改</a></p>
	        </div>

        <?php } ?>

      </div>
      <div class="col-md-12" style="margin-top:20px;">
      	<form class="form-inline" action="./add.php" method="post">
		  <div class="col-md-12">
		  	<div class="form-group">
		    <label for="exampleInputName2">Name</label>
		    <input type="text" class="form-control" id="exampleInputName2" name="username" placeholder="Jane Doe">
		  </div>
		  <button type="submit" class="btn btn-default">留言</button>
		  </div>
		  <div class="col-md-12" style="margin:20px 0px;">
		  	<textarea class="form-control" rows="3" style="width:100%" name="content"></textarea>
		  </div>
		</form>
      </div>
      <hr>

      <footer>
        <p>© 2016 Company, Inc.</p>
      </footer>
    </div> 
    <script type="text/javascript" src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function  () {
            
            $('.delBtn').click(function(event) {
                var id = $(this).attr('xbsid');
                delBtn = $(this);

                $.ajax({
                  url: './ajaxDel.php',
                  type: 'post',
                  dataType: 'json',
                  data: {msgid:id},
                })
                .done(function(data) {
                    if(data.error==0){
                      alert(data.info);
                      delBtn.parents('.msgRow').remove();
                    }
                })
                .fail(function(data) {
                  alert("失败");
                })
            });
        })
    </script>
  

</body>
</html>